<?php

namespace api\modules\v1\services;

use common\models\File;


/**
 * Class CourseContent
 * @package api\modules\v1\services
 */
class CourseContent extends \common\models\CourseContent
{
    /**
     * content添加素材路径
     * @name: fields
     * @return array
     * @author: rickeryu <lhyfe1987@163.com>
     * @time: 2017/12/6 下午3:51
     */
    public function fields() {
        $fields = parent::fields();
        $fields['file_url'] = function ($model) {
            if ($model->file_id != '-1') {
                $file = File::cacheFind($model->file_id,'id',true);
                $file['url'] = $file['server'].$file['key'];
                return $file;
            }
            return '';
        };
        return $fields;
    }
}